{ "cells": [ { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "\n", " var component = document.getElementById(\"sketch_14\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"state_14\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"controls_div_14\");\n", " if (component != undefined)\n", " component.remove();\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " // FIXME: Stop all previously running versions (?)\n", " var processingInstance = Processing.getInstanceById(\"canvas_14\");\n", " if (processingInstance != undefined && processingInstance.isRunning())\n", " processingInstance.noLoop();\n", " });\n", "\n", "\n", " var output_area = this;\n", " // find my cell element\n", " var cell_element = output_area.element.parents('.cell');\n", " // which cell is it?\n", " var cell_idx = Jupyter.notebook.get_cell_elements().index(cell_element);\n", " // get the cell object\n", " var cell = Jupyter.notebook.get_cell(cell_idx);\n", "\n", " function jyp_print(cell, newline) {\n", " return function(message) {\n", " cell.get_callbacks().iopub.output({header: {\"msg_type\": \"stream\"},\n", " content: {text: message + newline,\n", " name: \"stdout\"}});\n", " }\n", " }\n", " window.jyp_println = jyp_print(cell, \"\\n\");\n", " window.jyp_print = jyp_print(cell, \"\");\n", "\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " Processing.logger.println = jyp_print(cell, \"\\n\");\n", " Processing.logger.print = jyp_print(cell, \"\");\n", " });\n", "\n", "\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " Sketch #14:
\n", "
\n", "
\n", "
\n", " \n", " \n", " \n", " \n", "
\n", "Sketch #14 state: Loading...
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "void drawFish(int x, int y, float scale) {\n", " // fish tail\n", " fill(random(255), random(255), random(255));\n", " noStroke();\n", " //stroke(0);\n", " //strokeWeight(1);\n", " triangle(x, y,\n", " x + scale * 4, y + scale * 3,\n", " x, y + scale * 6);\n", " // fish body\n", " //fill(random(255), random(255), random(255));\n", " float centerOfBodyX = x + scale * 8;\n", " float centerOfBodyY = y + scale * 2;\n", " ellipse(centerOfBodyX, centerOfBodyY, 9 * scale, 7 * scale);\n", " // fish eye\n", " fill(0);\n", " ellipse(centerOfBodyX + scale * 3, centerOfBodyY + scale * -1, .5 * scale, .5 * scale);\n", " \n", " drawBubble(x + scale * 16, y + scale * 3, scale);\n", " drawBubble(x + scale * 20, y, scale * 2.0);\n", "}\n", "\n", "void drawBubble(float x, float y, float scale) {\n", " fill(204, 255, 255, 128);\n", " noStroke();\n", " ellipse(x, y, 3 * scale, 3 * scale);\n", "}\n", "\n", "void drawOcean() {\n", " background(0);\n", " fill(109, 219, 236);\n", " noStroke();\n", " rect(0, 0, 500, 500);\n", " // hook 1\n", " stroke(166, 192, 192);\n", " strokeWeight(4);\n", " arc(101, 65, 50, 70, 0, PI/2);\n", " line(100, 0, 100, 100);\n", " // hook 2\n", " arc(339, 165, 50, 70, PI/2, PI);\n", " line(340, 0, 340, 200);\n", " // hook 3\n", " arc(291, 350, 50, 70, 0, PI/2);\n", " line(290, 0, 290, 385);\n", "}\n", "\n", "void setup(){\n", " size(500,500);\n", "}\n", "\n", "void draw(){\n", " drawOcean();\n", " // For loop:\n", " for (int i = 0; i < 20; i++) {\n", " drawFish(int(random(500)), int(random(500)), 2 + random(3));\n", " }\n", " \n", " // While loop:\n", " int i = 0;\n", " while (i < 20) {\n", " drawFish(int(random(500)), int(random(500)), 2 + random(3));\n", " i++;\n", " }\n", " \n", " /*\n", " for(INIT; TEST; UPDATE) {\n", " ...\n", " }\n", "\n", " INIT;\n", " while (TEST) {\n", " ...\n", " UPDATE;\n", " }\n", " */\n", " noLoop();\n", "}" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "\n", " var component = document.getElementById(\"sketch_19\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"state_19\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"controls_div_19\");\n", " if (component != undefined)\n", " component.remove();\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " // FIXME: Stop all previously running versions (?)\n", " var processingInstance = Processing.getInstanceById(\"canvas_19\");\n", " if (processingInstance != undefined && processingInstance.isRunning())\n", " processingInstance.noLoop();\n", " });\n", "\n", "\n", " var output_area = this;\n", " // find my cell element\n", " var cell_element = output_area.element.parents('.cell');\n", " // which cell is it?\n", " var cell_idx = Jupyter.notebook.get_cell_elements().index(cell_element);\n", " // get the cell object\n", " var cell = Jupyter.notebook.get_cell(cell_idx);\n", "\n", " function jyp_print(cell, newline) {\n", " return function(message) {\n", " cell.get_callbacks().iopub.output({header: {\"msg_type\": \"stream\"},\n", " content: {text: message + newline,\n", " name: \"stdout\"}});\n", " }\n", " }\n", " window.jyp_println = jyp_print(cell, \"\\n\");\n", " window.jyp_print = jyp_print(cell, \"\");\n", "\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " Processing.logger.println = jyp_print(cell, \"\\n\");\n", " Processing.logger.print = jyp_print(cell, \"\");\n", " });\n", "\n", "\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " Sketch #19:
\n", "
\n", "
\n", "
\n", " \n", " \n", " \n", " \n", "
\n", "Sketch #19 state: Loading...
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "void setup() {\n", " size(400, 50);\n", "}\n", "\n", "int minimum(int a, int b, int c) {\n", " if (a <= b && a <= c) {\n", " return a;\n", " } else if (b <= a && b <= c) {\n", " return b;\n", " } else {\n", " return c;\n", " }\n", "}\n", "\n", "void draw() {\n", " background(255);\n", " fill(0);\n", " text(\"The minium of 3, 3, and 6 is:\" + minimum(3, 3, 6), 10, 20);\n", " noLoop();\n", "}" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Calysto Processing", "language": "java", "name": "calysto_processing" }, "language_info": { "codemirror_mode": { "name": "text/x-java", "version": 2 }, "file_extension": ".java", "mimetype": "text/x-java", "name": "java" } }, "nbformat": 4, "nbformat_minor": 2 }